package com.coding.controller;


import com.coding.base.pojo.BaseModel;
import com.coding.pojo.Poem;
import com.coding.pojo.User;
import com.coding.service.BackstageService;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@ResponseBody
@RequestMapping("backstage")
public class BackstageController {
    @Autowired
    BackstageService backstageService;

    @ApiOperation("获得用户列表")
    @ResponseBody
    @RequestMapping(value = "/getuserlist", method = RequestMethod.POST)
    public BaseModel getuserlist() throws Exception {
        BaseModel model = new BaseModel();
        backstageService.getuserlist(model);
        return model;
    }

    @ApiOperation(value = "获得新增用户id")
    @ResponseBody
    @RequestMapping(value = "/getnewuser_id", method = {RequestMethod.POST})
    public BaseModel getnewuser_id() throws Exception {
        BaseModel model = new BaseModel();
        backstageService.getnewuserid(model);
        return model;
    }

    @ApiOperation("新增用户")
    @ResponseBody
    @RequestMapping(value = "/addnewuser", method = RequestMethod.POST)
    public BaseModel addnewuser(@ModelAttribute User user) throws Exception {
        BaseModel model = new BaseModel();
        backstageService.insertuser(user, model);
        return model;
    }

    @ApiOperation("更改用户信息用户")
    @ResponseBody
    @RequestMapping(value = "/updateuser", method = RequestMethod.POST)
    public BaseModel updateuser(@ModelAttribute User user) throws Exception {
        BaseModel model = new BaseModel();
        backstageService.insertuser(user, model);
        return model;
    }

    @ApiOperation(value = "更改用户状态")
    @ResponseBody
    @RequestMapping(value = "/changeuser_status", method = {RequestMethod.POST})
    public BaseModel changeuser_status(@ApiParam("用户id") @RequestParam("user_id") int user_id) throws Exception {
        BaseModel model = new BaseModel();
        backstageService.changeuser_status(user_id, model);
        return model;
    }

    @ApiOperation(value = "删除用户")
    @ResponseBody
    @RequestMapping(value = "/deleteuser", method = {RequestMethod.POST})
    public BaseModel deleteuser(@ApiParam("用户id") @RequestParam("user_id") int user_id) throws Exception {
        BaseModel model = new BaseModel();
        backstageService.deleteuser(user_id, model);
        return model;
    }

    @ApiOperation(value = "获得诗词列表")
    @ResponseBody
    @RequestMapping(value = "/getpoemlist", method = {RequestMethod.POST})
    public BaseModel getpoemlist() throws Exception {
        BaseModel model = new BaseModel();
        backstageService.getpoemlist(model);
        return model;
    }

    @ApiOperation(value = "获得新增诗词id")
    @ResponseBody
    @RequestMapping(value = "/getnewpoem_id", method = {RequestMethod.POST})
    public BaseModel getnewpoem_id() throws Exception {
        BaseModel model = new BaseModel();
        backstageService.getnewpoemid(model);
        return model;
    }

    @ApiOperation(value = "新增诗词")
    @ResponseBody
    @RequestMapping(value = "/addnewpoem", method = {RequestMethod.POST})
    public BaseModel addnewpoem(@ModelAttribute Poem poem) throws Exception {
        BaseModel model = new BaseModel();
        backstageService.insertpoem(poem, model);
        return model;
    }

    @ApiOperation(value = "更新诗词")
    @ResponseBody
    @RequestMapping(value = "/updatepoem", method = {RequestMethod.POST})
    public BaseModel updatepoem(@ModelAttribute Poem poem) throws Exception {
        BaseModel model = new BaseModel();
        backstageService.updatepoem(poem, model);
        return model;
    }

    @ApiOperation(value = "删除诗词")
    @ResponseBody
    @RequestMapping(value = "/deletepoem", method = {RequestMethod.POST})
    public BaseModel deletepoem(@ApiParam("诗词") @RequestParam("poem") int poem_id) throws Exception {
        BaseModel model = new BaseModel();
        backstageService.deletepoem(poem_id, model);
        return model;
    }


}
